﻿<?php
require_once(dirname(__FILE__)."/../config/session.php");
//require_once("yz.php");
require_once(dirname(__FILE__)."/../config/config.inc.php");
require_once(dirname(__FILE__)."/../libs/string/libstr.php");
require_once(dirname(__FILE__)."/../libs/dbclass/dbconn.php");
require_once(dirname(__FILE__)."/../libs/dbclass/dbservice.php");
require_once(dirname(__FILE__)."/../libs/login/login.php");

$mc=new libstr();
$db=new dbconn();
$dbs=new dbservice();
$lp=new login();

include_once("arrtoxml.php");
$xm=new arraytoxml();
$mc_code=$_POST["mc_code"];

if($mc->Ismp($_POST["userid"])!="" && $mc->Ismp($_POST["password"])!="")
{
$mb=$db->ds("select userno,userid,username,password,pic,mc_code,isjihuo,jihuotime,youxiaotianshu,logintime,endtime,mc_codenum from member_content where userid='".trim($_POST["userid"])."' and password ='".strtoupper(md5(trim($_POST["password"])))."'");
	if(count($mb)>0)
	{
	
	if($mb[0]["isjihuo"]==0){
	$showtime=date("Y-m-d H:i:s");
	$youxiao=$mb[0]["youxiaotianshu"];
     $todata=date('Y-m-d H:i:s',strtotime($showtime ."+ ".$youxiao." day"));
	//exit( $todata);
	$db->cmd("update member_content set isjihuo=1,jihuotime='".$showtime."',endtime='".$todata."' where isjihuo=0 and userno=".$mb[0]["userno"]);
	
	}
	
	
	
	
	
	 
   // echo "2|login is ok,userno=".trim($mb[0]["userno"]).",password=".trim($mb[0]["password"]).",username=".trim($mb[0]["username"]).",pic=".trim($mb[0]["pic"]).",mc_code=".trim($mb[0]["mc_code"]);
	  $db->cmd("update member_content set logintime='".date('Y-m-d H:i:s',time())."' where userno=".$mb[0]["userno"]);
	
	if($mb[0]["mc_codenum"]!=0 && $mc_code!="" ){
	if(ereg($mc_code,$mb[0]["mc_code"])==1){
	
	
	}else{
	$strcode=$mb[0]["mc_code"].",".$mc_code;
	$db->cmd("update member_content set mc_codenum=mc_codenum-1, mc_code='".$strcode."' where userno=".$mb[0]["userno"]);
	}
	
	}
	$mb=$db->ds("select userno,userid,username,password,pic,mc_code,isjihuo,jihuotime,youxiaotianshu,logintime,endtime,mc_codenum from member_content where userno=".$mb[0]["userno"]);
	if(strtotime($mb[0]["endtime"])<time()){
	//exit("userid is gouqi");
	$mb[0]["guoqi"]=1;
	}else{
	$mb[0]["guoqi"]=0;
	}
	
	$mb[0]["nowtime"]=date('Y-m-d H:i:s',time());
	$mb[0]["isnumcode"]='false';
	if(ereg($mc_code,$mb[0]["mc_code"])==1)
	{
	$mb[0]["isnumcode"]='true';
	}
	echo $xm->getXML($mb);
	
	}else 
	{
  exit("1|userid or password is wrong");
	}
}else
{
  exit("0|userid or password is null");
}

?>